- Git
- what is Git?
- installing Git on your machine
- basic commands
- setting up a Git repo on a local machine
- GitHub
- what is GitHub?
- signing up
- connecting your local Git repo to GitHub
- selecting an awesome avatar will not be covered
July 27, 2017
There are a lot of different ways to use Git, for example, the command line, one of several desktop applications, and even within RStudio.
The basic Git workflow goes something like this:
Installation is rather straightforward: https://git-scm.com/downloads. Just follow the instructions for your particular operating system
Tip: Windows users, you should install from here: https://git-for-windows.github.io/
After Git is successfully installed, open up a terminal and write (with the obvious modifications) the following two lines:
$ git config --global user.name "Brandon Greenwell" $ git config --global user.email greenwell.brandon@gmail.com
Note: Since you passed the option --global, you only need to do this once!
Note: Technically, you don't need to do this step, but you should!
Note: Windows users should use the Bash terminal that was installed with Git, not the normal Windows command line!
cd (change directories)git init (initialize a folder as a Git repo)git add <file-name> (start tracking a new file)git commit -m "fix typo" (commit your changes)git clone (clone/copy another Git repo [e.g., from GitHub])git push origin master (push your master branch to your origin server)git pull origin master (update your local repo)Tip: Typing git add --all will start tracking everything (this is how I almost always use git add).
If you want to begin tracking an existing project in Git, you need to start by going to the project's root directory. For example,
cd C:/Users/greenweb/Desktop/devel/pkgbday
takes me to the sub folder called pkgday on my Desktop. Then, to initialize this as a Git repo, just type
git init
Tip: the command line has a history (just like the R console), so you don't need to type as often; just hit the up arrow and make any necessary changes!
If you want to start version controlling all the files, you need to start tracking them. In the terminal, type the following:
git add --all
then type:
git commit -m "very brief descriptive message"
Now Git will start tracking all the files in the repo. Whenever you make changes to ANY file in this repo, just retype the commands* with a new descriptive message:
git add --all git commit -m "added new plot function"
Tip: It's good practice to do this every time you make a key change (e.g., fix a typo, add a new function to an R script, etc.).
* Make sure you're in the right directory!
The first thing you need to do is set up an account: https://github.com/
Then go check your e-mail to verify the e-mail address you provided.